package com.admin.web.controller;

import com.admin.web.annotation.LogMenthodName;

import com.admin.web.controller.commen.BaseController;
import com.fegin.bean.admin.AdminRole;
import com.fegin.bean.common.layuiBean.ResultPage;
import com.fegin.bean.common.layuiBean.VoPage;
import com.fegin.client.admin.RoleFegin;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @author 张子艺
 * @packge com.admin.controller
 * @data 2019-01-15 18:07
 * @project currencycloud
 */
@Controller
@RequestMapping("/admin/role")
public class RoleController extends BaseController {
        @Autowired
        RoleFegin roleFegin;
    /**
     * 角色页面
     * @return
     */
    @RequestMapping(value = "/main.html", method = RequestMethod.GET)
    public Object login()   {
        return "system/role";
    }


    /**
     * 添加角色页面
     * @return
     */
    @RequiresPermissions("button:角色管理添加")
    @RequestMapping(value = "/roleAdd.html", method = RequestMethod.GET)
    public String roleAdd() {
        return "system/role_add";
    }


    /**
     * 角色表格查询
     * @param voPage
     * @return
     */
    @RequestMapping(value = "/findRole", method = RequestMethod.GET)
    @ResponseBody
    public ResultPage<AdminRole> findRoleByPage(VoPage voPage) {
        Long loginId=getUser().getId();
        return  roleFegin.findRoleByPage(voPage,1,loginId);
    }

    /**
     * 添加角色  AJAX
     * @param
     * @return
     */
    @LogMenthodName(name = "AOP环绕角色添加")
    @RequestMapping(value = "/insertRole", method = RequestMethod.POST)
    @ResponseBody
    @RequiresPermissions("button:角色管理添加")
    public Map<String, Object> insertRole(String roleName, String menuId) {

        return  roleFegin.insertRole(roleName,menuId ,getUser().getId());
    }
    /**
     * 角色所有查询
     * @return
     */
    @RequestMapping(value = "/findRoleAll", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> findRoleAll( ) {
        return  roleFegin.findRoleAll( getUser().getId(),1);
    }
    /**
     * 分销角色所有查询
     * @return
     */
    @RequestMapping(value = "/findRoleAllByPeople", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> findRoleAllByPeople( ) {
        return  roleFegin.findRoleAll( getUser().getId(),2);
    }


    /**
     * 删除角色  AJAX
     * @param
     * @return
     */
    @LogMenthodName(name = "AOP环绕角色删除")
    @RequestMapping(value = "/delRole", method = RequestMethod.POST)
    @ResponseBody
    @RequiresPermissions("button:角色管理删除")
    public Map<String, Object> delRole(  Long roleId) {
        return  roleFegin.delRole(roleId);
    }


    /**
     * 分销级别页面
     * @return
     */
    @RequestMapping(value = "/level.html", method = RequestMethod.GET)
    public String distribution() {
        return "distribution/level";
    }

    /**
     * 分销级别添加页面
     * @return
     */
    @RequestMapping(value = "/distributionAdd.html", method = RequestMethod.GET)
    public String distributionAdd() {
        return "distribution/level_add";
    }
    /**
     * 分销级别添加
     * @return
     */
    @LogMenthodName(name = "AOP环绕分销商添加")
    @RequestMapping(value = "/insertDistribution" )
    @ResponseBody
    public Map<String, Object> insertDistribution(String roleName, String menuId) {
        Long userId=getUser().getId();
        return   roleFegin.insertDistribution(roleName,menuId,userId);
    }

    /**
     * 分销商表格查询
     * @param voPage
     * @return
     */
    @RequestMapping(value = "/findDistribution", method = RequestMethod.GET)
    @ResponseBody
    public ResultPage<AdminRole> findDistribution(VoPage voPage) {
        return  roleFegin.findRoleByPage(voPage,2,getUser().getId());
    }
}
